var form = layui.form


form.verify({
    username: function(value, item) {
        if (!new RegExp("^[a-zA-Z0-9@._\u4e00-\u9fa5\\s·]+$").test(value)) {
            return '用户名不能有特殊字符';
        }
        if (/(^\_)|(\__)|(\_+$)/.test(value)) {
            return '用户名首尾不能出现下划线\'_\'';
        }
        if (/^\d+\d+\d$/.test(value)) {
            return '用户名不能全为数字';
        }
        if (value === 'xxx') {
            return ('用户名不能为敏感词');
        }
    },
    pwd: [
        /^[\S]{5,12}$/, '密码必须6到12位，且不能出现空格'
    ]
});

$("#form_login").submit(function(e) {
    e.preventDefault()
    let data = {
        username: $('[name=username]').val(),
        password: $('[name=password]').val(),
    }
    $.ajax({
        url: '/api/login',
        method: 'POST',
        data: data,
        success: function(res) {
            if (res.status !== 0) {
                return layer.msg('登录失败')
            }
            layer.msg('登录成功！')
            localStorage.setItem('token', res.token)
            location.href = 'http://127.0.0.1:5500/jiang-qiliang-group-project/bigevent-end/index.html'

        }
    })
})